import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//全局引入axios
import axios from 'axios'

const app = createApp(App);

//配置全局路径
axios.defaults.baseURL = "http://localhost:8080/app"
//将axios挂载到app对象上
app.config.globalProperties.$axios = axios
//跨域请求中传递cookie
axios.defaults.withCredentials = true

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
	console.log('响应拦截器：',response);
	if(response.data.code == 50001){
		router.push("/login");
	}
    return response;
  }, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
  });

// 1. 引入你需要的组件
import { Button, Tabbar, TabbarItem, Col, Row, Icon } from 'vant';
import { Swipe, SwipeItem } from 'vant';
import { List, PullRefresh } from 'vant';
import { Notify } from 'vant';
import { Popup } from 'vant';
import { Card } from 'vant';
import { SubmitBar } from 'vant';
import { showToast } from 'vant';
import { ContactList } from 'vant';
import { AddressList } from 'vant';
import { AddressEdit } from 'vant';
import { Area } from 'vant';
import { Form, Field, CellGroup } from 'vant';
import { Image as VanImage } from 'vant';
import { FloatingPanel } from 'vant';
import { TextEllipsis } from 'vant';
import { Barrage } from 'vant';
// 2. 引入组件样式
import 'vant/lib/index.css';


//路由守卫
router.beforeEach((to,from,next)=>{
	console.log('路由守卫：',to, to.path);
	store.state.activeTab = to.path;   //手动输入路由地址时更新激活的导航
	next(); //放行
})

app.use(Button);
app.use(Tabbar);
app.use(TabbarItem);
app.use(Col);
app.use(Row);
app.use(Icon);
app.use(Swipe);
app.use(SwipeItem);
app.use(List);
app.use(PullRefresh);
app.use(Notify);
app.use(Popup);
app.use(Card);
app.use(SubmitBar);
app.use(showToast);
app.use(ContactList);
app.use(AddressList);
app.use(AddressEdit);
app.use(Area);
app.use(Form);
app.use(Field);
app.use(CellGroup);
app.use(VanImage);
app.use(FloatingPanel);
app.use(TextEllipsis);
app.use(Barrage);
app.use(store).use(router).mount('#app')